package com.lxgzhw.student_manager02.service.impl;

import com.lxgzhw.student_manager02.dao.UserDao;
import com.lxgzhw.student_manager02.domain.Result;
import com.lxgzhw.student_manager02.domain.User;
import com.lxgzhw.student_manager02.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserServiceImpl implements UserService {
    @Autowired
    private UserDao userDao;

    @Override
    public void add(User user) {
        userDao.save(user);
    }

    @Override
    public boolean find(User user) {
        boolean flag = false;
        User user1 = userDao.findByUsernameAndPassword(user.getUsername(), user.getPassword());
        if (user1 != null) {
            flag = true;
        }
        return flag;
    }

    @Override
    public Result<User> page(Integer page, Integer limit) {
        long count = userDao.count();
        List<User> users=userDao.findLimit((page-1)*limit,limit);
        Result<User> userResult = new Result<>();
        userResult.setCode(0);
        userResult.setMsg("");
        userResult.setCount(count);
        userResult.setData(users);
        return userResult;
    }
}
